import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

// 文本消息气泡组件
class TextMessageBubble extends StatelessWidget {
  final String text;
  final bool isMe;
  final int status;

  const TextMessageBubble({
    super.key,
    required this.text,
    required this.isMe,
    required this.status,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 12.h),
      decoration: BoxDecoration(
        color: isMe ? Colors.blue[100] : Colors.grey[200],
        borderRadius: BorderRadius.circular(12.r),
      ),
      child: Text(text, style: TextStyle(fontSize: 28.sp)),
    );
  }
}

// 图片消息气泡组件
class ImageMessageBubble extends StatelessWidget {
  final String url;
  final bool isMe;

  const ImageMessageBubble({super.key, required this.url, required this.isMe});

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(8.r),
      child: Container(
        constraints: BoxConstraints(
          maxHeight: 240.h
        ),
        child: CachedNetworkImage(
          fit: BoxFit.fitWidth,
          imageUrl: '$url?t=${DateTime.now().millisecondsSinceEpoch}',
          progressIndicatorBuilder: (context, url, progress) {
            return Center(
              child: CircularProgressIndicator(
                value: 0.5, // 显示下载进度（0.0 ~ 1.0）
              ),
            );
          },
          errorWidget: (context, url, error) => Icon(Icons.error),
          fadeInDuration: Duration(seconds: 5),
        ),
      ),
    );
  }
}
